package com.langxin.site.biz;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.langxin.site.dao.TourDao;
import com.langxin.site.model.PageInfo;
import com.langxin.site.model.TourInfo;
import com.langxin.site.model.vo.QueryVo;
import com.langxin.site.util.constant.SiteConstant;

/**
 * 旅游biz
 * @author guqj
 *
 */
@Service
public class TourBiz extends BaseBiz{

	@Autowired
	private TourDao  tourDao;
	
	/**
	 * 条件查询
	 * @param baseVo   参数
	 * @param pageSize 每页记录数
	 * @return
	 */
	public List<TourInfo> queryList(QueryVo queryVo, Integer pageSize){
		if(queryVo == null){
			queryVo = new QueryVo();
		}
		if(pageSize != null){
			queryVo.setPageSize(pageSize);
		}
		if(queryVo.getPage()==null || queryVo.getPage().compareTo(1) < 0){
			queryVo.setPage(1);
		}
		return tourDao.query(queryVo);
	}
	
	/**
	 * 精品推荐
	 * @return
	 */
	public List<TourInfo> queryGifts(Integer num){
		QueryVo queryVo = new QueryVo();
		queryVo.setIsGifts(1);
		return queryList(queryVo, num);
	}
	
	/**
	 * 总数
	 * @param queryVo
	 * @return
	 */
	public Integer queryNum(QueryVo queryVo){
		return tourDao.queryNum(queryVo);
	}
	
	/**
	 * 分页
	 * @param queryVo
	 * @param pageInfo
	 */
	public void queryPage(QueryVo queryVo, PageInfo<TourInfo> pageInfo){
		pageInfo.setRecords(queryList(queryVo, 16));
		pageInfo.setTotalCount(queryNum(queryVo));
		pageInfo.fill(queryVo);
	}
	
	/**
	 * 详情
	 * @param id
	 * @return
	 */
	public TourInfo queryById(Integer id){
		if(!isRead(SiteConstant.CookieKey.TOUR_KEY.getValue(), id)){
			tourDao.updateReadTime(id);
		}
		return tourDao.queryById(id);
	}
}
